package com.nowcoder.code.lcof;

import com.algorithm.model.TreeNode;

public class JZ54 {

    public static void main(String[] args) {

    }



    public int KthNode(TreeNode proot, int k) {
        if (proot == null || k == 0) {
            return -1;
        }
        return preOrder(proot, k);
    }


    int ik = 0;

    public int preOrder(TreeNode node, int k) {
        if (node == null) {
            return -1;
        }

        int j = preOrder(node.left, k);
        if (j != -1) {
            return j;
        }
        ik++;
        if (ik == k) {
            return node.val;
        }
        return preOrder(node.right, k);

    }


}
